# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

pkgname=rz-ghidra
_gitcommit=1ed04d6c29b1a8226f0c0cdf8163def4b2fb0b1e
_gitcutter=c0f260ca6913f3928259309766692e50131f7270
pkgver=0.5.0
pkgrel=1
pkgdesc='Deep ghidra decompiler integration for rizin and rz-cutter'
url='https://github.com/rizinorg/rz-ghidra'
arch=('loong64' 'x86_64')
license=('LGPL3')
depends=('rizin' 'glibc')
makedepends=('git' 'cmake' 'qt5-base' 'rz-cutter')
source=("git+${url}#commit=${_gitcommit}"
        "git+https://github.com/rizinorg/cutter#commit=${_gitcutter}"
        rizin-ghidra::git+https://github.com/rizinorg/ghidra.git
        git+https://github.com/zeux/pugixml.git)
sha512sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP')

pkgver() {
  cd ${pkgname}
  git describe --tags --match 'rz-*' | sed 's/^rz-//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd ${pkgname}
  git submodule init
  git config submodule."third-party/pugixml".url "${srcdir}/pugixml"
  git config submodule."ghidra/ghidra".url "${srcdir}/rizin-ghidra"
  git -c protocol.file.allow=always submodule update --recursive
}

build() {
  cd ${pkgname}
  cmake \
    -B build \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DBUILD_CUTTER_PLUGIN=ON \
    -DBUILD_SLASPECS=ON \
    -DCUTTER_SOURCE_DIR="${srcdir}/cutter" \
    -DCUTTER_INSTALL_PLUGDIR=/usr/share/rizin/cutter/plugins/native
  make -C build VERBOSE=1
}

package() {
  cd ${pkgname}
  make -C build -j1 DESTDIR="${pkgdir}" install
}

# vim: ts=2 sw=2 et:
